package com.group.yztcedu.playlive.main.home.adapter;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.group.yztcedu.playlive.R;
import com.group.yztcedu.playlive.bean.HomeLivesBean;
import com.group.yztcedu.playlive.bean.HomeRecommendTagsBean;
import com.group.yztcedu.playlive.main.home.loadmore.LoadMoreActivity;
import com.group.yztcedu.playlive.widget.MyGridView;

import java.util.List;


public class ListViewAdapter extends BaseAdapter {
    private List<HomeRecommendTagsBean> mList;
    public ListViewAdapter(List<HomeRecommendTagsBean> list){
        this.mList = list;
    }
    @Override
    public int getCount() {
        return mList!=null?mList.size():0;
    }

    @Override
    public Object getItem(int i) {
        return mList!=null?mList.get(i):null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, final ViewGroup viewGroup) {
       ViewHolder holder;
        if(view==null){
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.home_listview_item,null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }
        HomeRecommendTagsBean homeRecommendTagsBean = mList.get(i);

        final String name = homeRecommendTagsBean.getName();
        List<HomeLivesBean> lives = homeRecommendTagsBean.getLives();
        holder.name.setText(name);
        HomeRecommendAdapter adapter = new HomeRecommendAdapter(lives);
        holder.myGridView.setAdapter(adapter);
        holder.loadMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               // if(!"王者荣耀".equals(name)){
                    Intent intent = new Intent(viewGroup.getContext(), LoadMoreActivity.class);
                    intent.putExtra("name",name);
                    viewGroup.getContext().startActivity(intent);
              //  }else{
                //    Intent intent = new Intent(viewGroup.getContext(), LoadMoreKingActivity.class);
                //    viewGroup.getContext().startActivity(intent);
           //     }

            }
        });
        return view;
    }
    class ViewHolder{
        private TextView name,loadMore;
        private MyGridView myGridView;
        public ViewHolder(View view){
            name = (TextView) view.findViewById(R.id.home_title_cy);
            loadMore = (TextView) view.findViewById(R.id.fire_more);
            myGridView = (MyGridView) view.findViewById(R.id.home_gridView_cy);

        }
    }
}
